package com.hengpeng.itfinoss.service.bankproduct.impl;

import java.util.List;

import org.hibernate.util.StringHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import com.hengpeng.common.exception.ServiceResult;
import com.hengpeng.common.persist.QueryResult;
import com.hengpeng.common.persist.query.DynamicQuery;
import com.hengpeng.common.persist.query.constants.QueryConstants.QueryType;
import com.hengpeng.itfinbase.persist.BankProduct;
import com.hengpeng.itfinbase.persist.BankProductContacts;
import com.hengpeng.itfinoss.service.ServiceFactory;
import com.hengpeng.itfinoss.service.bankproduct.BankProductService;

@Lazy
@Service
public class BankProductServiceImpl implements BankProductService
{
	@Autowired
	private ServiceFactory serviceFactory;

	@Override
	public ServiceResult<List<BankProduct>> queryList(String name, Integer pageIndex, Integer pageSize)
	{
		DynamicQuery query = new DynamicQuery(BankProduct.class);
		if (!StringHelper.isEmpty(name)) {
			query.like("name", "%" + name + "%");
		}
		query.desc("createTime");
		query.setPageIndex(pageIndex);
		query.setPageSize(pageSize);
		query.setQueryType(QueryType.JDBC);
		query.setIsSearchTotalCount(true);
		QueryResult<BankProduct> requery = serviceFactory.getPersistService().findWithPage(BankProduct.class, query);
		Long count = requery.getTotalCount();
		ServiceResult<List<BankProduct>> serviceResult = new ServiceResult<List<BankProduct>>();// 设置返回值
		serviceResult.setReturnValue(requery.getResults());
		serviceResult.setReturnListSize(count.intValue());
		return serviceResult;
	}

	@Override
	public ServiceResult<List<BankProductContacts>> queryContactsList(Long id,
			Integer pageIndex, Integer pageSize) {
		DynamicQuery query = new DynamicQuery(BankProductContacts.class);
		if (id != null) {
			query.eq("bankProductId", id);
		}
		query.desc("createTime");
		query.setPageIndex(pageIndex);
		query.setPageSize(pageSize);
		query.setQueryType(QueryType.JDBC);
		query.setIsSearchTotalCount(true);
		QueryResult<BankProductContacts> requery = serviceFactory.getPersistService().findWithPage(BankProductContacts.class, query);
		Long count = requery.getTotalCount();
		ServiceResult<List<BankProductContacts>> serviceResult = new ServiceResult<List<BankProductContacts>>();// 设置返回值
		serviceResult.setReturnValue(requery.getResults());
		serviceResult.setReturnListSize(count.intValue());
		return serviceResult;
	}
	
}
